package com.beniceee;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.benice.model.User;

@RestController
@RequestMapping("/user")
public class UserController {
	@RequestMapping(value = "/check", method = RequestMethod.GET,headers="Accept=application/json")
	public String getGreeting(@RequestParam String name) {
		String result="Hello "+name;
		System.out.println();
		return result;
	}
	
	@RequestMapping(value = "getAllUsers",method = RequestMethod.GET,headers="Accept=application/json")
	 public List<User> getAllUsers() {
	  List<User> users= new ArrayList<User>();
//	  users.add(new User("Nam","47"));
//	  users.add(new User("Ninh","48"));
	  return users;
	 }
	
	@RequestMapping(value ="/createUser", method = RequestMethod.POST,headers="Accept=application/json")
	 public User createUser(@RequestParam User user,@RequestHeader("User-Agent") String requestHeader) {
	  System.out.println("###########" + user);
	  System.out.println("###########Header   " + requestHeader);
	  System.out.println(user.getName());
//	  System.out.println(user.getAge());
	  user.setName("Teo");
	  return user;
	 }
	
}